package com.gxa.modules.property.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.gxa.modules.property.dto.ComplaintDto;
import com.gxa.modules.property.dto.ComplaintToUpdate;
import com.gxa.modules.property.entity.Complaint;
import com.gxa.modules.property.entity.ComplaintType;
import com.gxa.modules.property.mapper.ComplaintMapper;
import com.gxa.modules.property.service.ComplaintService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class ComplaintServiceImpl implements ComplaintService {

    @Autowired
    private ComplaintMapper complaintMapper;
    @Override
    public void add(ComplaintDto complaintDto) {
        this.complaintMapper.add(complaintDto);
    }

    @Override
    public void delete(Integer id) {
        this.complaintMapper.delete(id);
    }

    @Override
    public void update(ComplaintToUpdate complaintToUpdate) {
        this.complaintMapper.update(complaintToUpdate);
    }

    @Override
    public PageInfo<Complaint> queryComplaint(Map<String,Object> params) {
        String page1 = (String) params.get("page");
        String limit1 = (String) params.get("limit");
        Integer page = Integer.valueOf(page1);
        Integer limit = Integer.valueOf(limit1);

        //条件查询
        String stateId = (String) params.get("stateId");
        String complainant = (String) params.get("complainant");
        String communityId = (String) params.get("communityId");

        PageHelper.startPage(page,limit);
        List<Complaint> complaintList = complaintMapper.queryComplaint(stateId,complainant,communityId);
        PageInfo<Complaint> pageInfo = new PageInfo<>(complaintList);
        return pageInfo;
    }

    @Override
    public List<ComplaintType> queryComplaintType() {
        return complaintMapper.queryComplaintType();
    }
}
